<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_DEAN . 'faculty.html'));
	
	$urlPage 	= _GET('page');
	#SEARCH
	$search 	= _GET('search', false);
	if ( empty($search) ) {
		$search = "Search here...";
	}
	$listCountPersonalInformation = $PI->listCountPersonalInformation($search, "'P'", $strAccDept); //COUNT

	if( $listCountPersonalInformation > 0 ) {
		$countNum			= 20;
		$pagenum 			= $_GET["page_no"];
		$page_rows 			= $PAGINATION->numPerRow($countNum);
		$last 				= $PAGINATION->lastCeilPerRow($listCountPersonalInformation, $page_rows);
		$pagenum 			= $PAGINATION->pageNumRow($pagenum, $last); 
		$pageLimit 			= $PAGINATION->limitRow($pagenum, $page_rows);
		
		$arrBut				= array('first' 	=> '<img src="' . DIR_IMAGES . 'pagination_first.png" title="First" border="0" />',
									'previous' 	=> '<img src="' . DIR_IMAGES . 'pagination_prev.png" title="Previous" border="0" />',
									'next' 		=> '<img src="' . DIR_IMAGES . 'pagination_next.png" title="Next" border="0" />',
									'last' 		=> '<img src="' . DIR_IMAGES . 'pagination_last.png" title="last" border="0" />',);
		$classCSS			= array('button' 	=> 'pagination-button', 'label' 	=> 'pagination-label');
		$urlGet				= array('page' 		=> $_GET['page'], 		'search' 	=> $search);
		
		if( $listCountPersonalInformation > $countNum ) {
			$pagination 	= $PAGINATION->pagination($arrBut, $pagenum, $last, $classCSS, $urlGet);
		}
	}
		
	$PIList = $PI->listPersonalInformation($search, $pageLimit, "'P'", $strAccDept);
	
	# LSITING
	if ( !empty($PIList) ) {
		
		$TEMP->set_block('handle',  'accounts', 'accountsRow');
		$bgcolor 	= LOOPING_F0F;
		$numCount 	= 1;
		
		if ( intval($_GET['page_no']) > 1 ) {
			$countNumSub = intval($_GET['page_no']);
			$numCount += intval($_GET['page_no'] - 1) * $countNum;
		}
			
		foreach($PIList as $PIListField => $PIListValue) {
			
			switch ( $PIListValue['account_type'] ) {
				case 'A': $accountType = "Administrator"; break;
				case 'R': $accountType = "Registrar"; 	  break;
				case 'P': $accountType = "Faculty"; 	  break;
				case 'D': $accountType = "Dean"; 		  break;
				default: $accountType = ""; 			  break;
			}
			
			if ( $PIListValue['user_idPK'] != $logUserID && $PIListValue['is_deleted'] == 'N') {
				$edButton = '<div class="icon-button">
								&nbsp;&nbsp;<img src="' . DIR_IMAGES . 'icon/profile.png" border="0" title="View Profile" onclick="popupRequest(\'show\', \'ViewProfile\', \'Profile Account\', \'280\', \'500\', \'' . $PIListValue['user_idPK'] . '\');"/>
							</div>';
			}
			else {
				$edButton = '&nbsp;&nbsp;<img src="' . DIR_IMAGES . 'icon/profile_d.png" border="0" title="View Profile"/>';
			}
			
			$hashRandomF = hashRandom($PIListValue['user_idPK'] . $PIListValue['account_no']. $PIListValue['last_name'] . ', ' . $PIListValue['first_name'] . ' ' . $PIListValue['middle_name'] . $PIListValue['email'].time());
			
			$profSubjTotalUnits = $STUD->getTotalUnitsProfSubj($PIListValue['user_idPK']);
			
			$TEMP->set_var(array('user_id' 		=> $PIListValue['user_idPK'],
								 'account_no' 	=> $PIListValue['account_no'],
								 'name' 		=> $PIListValue['last_name'] . ', ' . $PIListValue['first_name'] . ' ' . $PIListValue['middle_name'],
								 'total_hrs'	=> $profSubjTotalUnits . ' Unit(s)',
								 'email' 		=> $PIListValue['email'],
								 'subject'		=> '<a href="?page=FacultyAssignCourse&fid=' . $PIListValue['user_idPK'] . '&hash=' . $hashRandomF . '"><img src="' . DIR_IMAGES . 'icon/arrow_down.png" border="0" title="Assign Subjects"/></a>',
								 'schedules'	=> '<a href="?page=FacultySchedules&fid=' . $PIListValue['user_idPK'] . '&hash=' . $hashRandomF . '"><img src="' . DIR_IMAGES . 'icon/sched.png" border="0" title="Schedules"/></a>',
								 'account_type'	=> $accountType,
								 'is_deleted' 	=> ($PIListValue['is_deleted'] == 'N') ? 'enabled' : 'disabled',
								 'numbering'	=> $numCount,
								 'bgcolor'		=> $bgcolor,
								 'ed_button'	=> $edButton
								));
								
			$TEMP->parse('accountsRow', 'accounts', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
		}
	}
	else {
		$TEMP->set_var(array('user_id' 		=> '',
							 'account_no' 	=> '',
							 'name' 		=> '',
							 'total_hrs'	=> '',
							 'email' 		=> '',
							 'subject'		=> '',
							 'schedules'	=> '',
							 'account_type'	=> '',
							 'is_deleted' 	=> '',
							 'numbering'	=> '',
							 'bgcolor'		=> '',
							 'ed_button'	=> '',
							));
	}
	
	$TEMP->set_var(array('search' 			=> $search,
						 'pagination'		=> $pagination,
						 'results'			=> "<strong>" . $listCountPersonalInformation . "</strong> results",
						 'urlPage'			=> $urlPage,
						 'dean_sub_menu'	=> $pageLib->deanSubMenu(DIR_IMAGES),
						 'dept_course'		=> $strAccCourse,
						));
?>